package com.putao.tinytime.base;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

import com.putao.tinytime.interfaces.IActivityInterface;

public abstract class BaseActivity extends FragmentActivity implements IActivityInterface {
    public Context mContext;
    public Activity mActivity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        doBefore();
        View containerView = getLayoutInflater().inflate(doGetContentViewId(), null);
        setContentView(containerView);
        init();
        doInitSubViews(containerView);
        doInitData();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    private void init() {
        mActivity = this;
        mContext = this;
    }

    /**
     * set OnClickListener for every View
     *
     * @param views
     */
    protected void addOnClickListener(View... views) {
        OnClickListener listener = (OnClickListener) mActivity;
        if (listener != null)
            for (int i = 0; i < views.length; i++)
                views[i].setOnClickListener(listener);
    }

    public void doBefore() {
    }

    protected void showToast(String message) {
        Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
    }

    //获取版本号(内部识别号)
    public int getVersionCode(Context context)
    {
        try {
            PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            return pi.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return 0;
        }
    }


//    protected void fullScreen(boolean enable) {
//        if (enable) {
//            WindowManager.LayoutParams lp = getWindow().getAttributes();
//            lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
//            getWindow().setAttributes(lp);
//            getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
//        } else {
//            WindowManager.LayoutParams attr = getWindow().getAttributes();
//            attr.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
//            getWindow().setAttributes(attr);
//            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
//        }
//        isFullScreen = enable;
//    }
}
